package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhAfterParts;
import com.ruoyi.zsyh.service.IZsyhAfterPartsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 售后平台自购配件Controller
 * 
 * @author yuexl
 * @date 2022-08-22
 */
@Controller
@RequestMapping("/zsyh/afterParts")
public class ZsyhAfterPartsController extends BaseController
{
    private String prefix = "zsyh/afterParts";

    @Autowired
    private IZsyhAfterPartsService zsyhAfterPartsService;

    @RequiresPermissions("zsyh:afterParts:view")
    @GetMapping()
    public String afterParts()
    {
        return prefix + "/afterParts";
    }

    /**
     * 查询售后平台自购配件列表
     */
    @RequiresPermissions("zsyh:afterParts:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhAfterParts zsyhAfterParts)
    {
        startPage();
        List<ZsyhAfterParts> list = zsyhAfterPartsService.selectZsyhAfterPartsList(zsyhAfterParts);
        return getDataTable(list);
    }

    /**
     * 导出售后平台自购配件列表
     */
    @RequiresPermissions("zsyh:afterParts:export")
    @Log(title = "售后平台自购配件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhAfterParts zsyhAfterParts)
    {
        List<ZsyhAfterParts> list = zsyhAfterPartsService.selectZsyhAfterPartsList(zsyhAfterParts);
        ExcelUtil<ZsyhAfterParts> util = new ExcelUtil<ZsyhAfterParts>(ZsyhAfterParts.class);
        return util.exportExcel(list, "售后平台自购配件数据");
    }

    /**
     * 新增售后平台自购配件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存售后平台自购配件
     */
    @RequiresPermissions("zsyh:afterParts:add")
    @Log(title = "售后平台自购配件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhAfterParts zsyhAfterParts)
    {
        return toAjax(zsyhAfterPartsService.insertZsyhAfterParts(zsyhAfterParts));
    }

    /**
     * 修改售后平台自购配件
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhAfterParts zsyhAfterParts = zsyhAfterPartsService.selectZsyhAfterPartsById(id);
        mmap.put("zsyhAfterParts", zsyhAfterParts);
        return prefix + "/edit";
    }

    /**
     * 修改售后平台自购配件
     */
    @GetMapping("/viewDetail/{id}")
    public String viewDetail(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhAfterParts zsyhAfterParts = zsyhAfterPartsService.selectZsyhAfterPartsById(id);
        mmap.put("zsyhAfterParts", zsyhAfterParts);
        return prefix + "/viewDetail";
    }

    /**
     * 修改保存售后平台自购配件
     */
    @RequiresPermissions("zsyh:afterParts:edit")
    @Log(title = "售后平台自购配件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhAfterParts zsyhAfterParts)
    {
        return toAjax(zsyhAfterPartsService.updateZsyhAfterParts(zsyhAfterParts));
    }

    /**
     * 删除售后平台自购配件
     */
    @RequiresPermissions("zsyh:afterParts:remove")
    @Log(title = "售后平台自购配件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhAfterPartsService.deleteZsyhAfterPartsByIds(ids));
    }
}
